﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace QuanLyThuNgan
{
    public class DonVi_Khac
    {
        private static string _ConnectS5;
        private static string _ConnectPhkham_S3;
        public static string ConnectS5
        {
            get { return _ConnectS5; }
            set {_ConnectS5  = value; }
        }
        public static string ConnectPhkham_S3
        {
            get { return _ConnectPhkham_S3; }
            set { _ConnectPhkham_S3 = value; }
        }
        public DataTable SelectDonVi_TheoCa()
        {
            string _sql = string.Format("dbo.usp_ThuNgan_DonVi_Ca");
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable SelectTinhThanh()
        {
            string _sql = string.Format("dbo.usp_ThuNgan_TinhThanh_Select");
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable SelectQuanHuyen()
        {
            string _sql = string.Format("dbo.usp_ThuNgan_QuanHuyen_Select");
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable DMDonVi()
        {
            string _sql = string.Format("dbo.usp_ThuNgan_DMDonVi_SelectAll");
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable DMBacSi()
        {
            string _sql = string.Format("dbo.usp_ThuNgan_BacSi_All");
            return Uit.it_SQL.getDataTable(_sql);
        }
        #region"NgoaiTRu"
        public DataTable TimKiemBNNgoaiTru(string sohs,string ho,string ten,int namsinh,int idtinh,int idhuyen)
        {
            string _sql = string.Format("exec dbo.usp_HIS_DM_BenhNhan_ThuTienDichVuNgoaiTru '{0}',N'{1}',N'{2}',{3},{4},{5}",sohs, ho,ten,namsinh,idtinh,idhuyen);
            return Uit.it_SQL.getDataTable(_sql);
        }
      
        public  DataTable LayDSDVTChuyenDoi()
        {
            DataTable dt = LayDSDVTChuyenDoi_();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["donviold"] = Uit.it_Font.VNIToUnicode(dt.Rows[i]["donviold"].ToString().Trim());
                dt.Rows[i]["donvinew"] = Uit.it_Font.VNIToUnicode(dt.Rows[i]["donvinew"].ToString().Trim());
            }
            return dt;
        }
        public DataTable LayDSDVTChuyenDoi_()
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_ChuyenDoiDVT");
            return Uit.it_SQL.getDataTable(_sql);
        }
        public  string DVTChuyenDoi(string DVTCu)
        {
            string ret = DVTCu;
            DataTable _dvtConvert= LayDSDVTChuyenDoi();
            for (int i = 0; i < _dvtConvert.Rows.Count; i++)
            {
                if (_dvtConvert.Rows[i]["donviold"].ToString().ToUpper() == DVTCu.Trim().ToUpper())
                {
                    ret = _dvtConvert.Rows[i]["donvinew"].ToString().ToUpper();
                    break;
                }
            }
            return ret;
        }
        public object DonViTuLoaidichVu( string loai)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_LoaiDvu_Madv {0}",loai);
            return Uit.it_SQL.ExecuteScalar(_sql);
        }
        public DataTable LoadDSPhieu(string sohs,string ngay)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_LoadDanhSachPhieuBenhNhanTrongNgay '{0}','{1}'", sohs,ngay);
            return Uit.it_SQL.getDataTable(_sql);
        }
        #endregion
        #region "NoiTru"
        
        public DataTable TimKiemDSBNNoiTru(string sohs,string ho,string ten,int namsinh,string sonhapvien,string traibenh,string tungay,string denngay)
        {
            string _sql = string.Format("exec dbo.usp_HIS_DM_BenhNhan_ThuTienNoiTru '{0}',N'{1}',N'{2}',{3},'{4}','{5}','{6}','{7}'", sohs, ho, ten, namsinh, sonhapvien, traibenh,tungay, denngay);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable TimKiemBNNoiTru_TamUng(string sohs,string ho,string ten,int namsinh,string sonhapvien,string traibenh)
        {
            string _sql = string.Format("exec dbo.usp_HIS_DM_BenhNhan_ThuTienTamUng '{0}',N'{1}',N'{2}',{3},'{4}','{5}'", sohs, ho, ten, namsinh, sonhapvien, traibenh);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable DSPhieuNopTien(string sohs, string sonhapvien)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_LoadDanhSachPhieuNopTien '{0}','{1}'", sohs,sonhapvien);
            return Uit.it_SQL.getDataTable(_sql);
        }
       
        public DataTable DSPhieuNop_Noi_Ngoai(string sohs, string sonhapvien, int idcathungan, int loaibn)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_LoadDSBN_Ngoai_NoiTru '{0}','{1}',{2},{3}", sohs,sonhapvien,idcathungan,loaibn);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable TimKiemBNNoiTru_Ngoai(string sohs, string ho, string ten, int namsinh, string sonhapvien, string traibenh, int idcathungan, int loaibn)
        {
            string _sql = string.Format("exec dbo.usp_HIS_DM_BenhNhan_XacNhan '{0}',N'{1}',N'{2}',{3},'{4}','{5}',{6},{7}", sohs, ho, ten, namsinh, sonhapvien, traibenh,idcathungan, loaibn);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public bool Update_Thudlt_BafeeMst( string sobn ,int loaibn)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_XacNhanThuTien_Bafee_Thudlt '{0}',{1}", sobn,loaibn);
            return Uit.it_SQL.ExecuteNonQuery(_sql);
        }
        public DataTable LoadDSPhieu_NoiTru(string sohs, string ngay)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_LoadDanhSachPhieuBenhNhanTrongNgay_NoiTru '{0}','{1}'", sohs, ngay);
            return Uit.it_SQL.getDataTable(_sql);
        }
        #endregion
        #region "Thuoc noi tru"
        public DataSet Load_All_DanhMuc_ToaThuoc()
        {
            string _sql = string.Format(" exec dbo.usp_ThuNgan_ToaThuocNoiTru_CacDMuc");
            return Uit.it_SQL.getDataSet(_sql,false);
        }
        public DataTable LayDSDVD()
        {
            string str = string.Format("exec dbo.usp_ThuNgan_LayDsDVD");
            return Uit.it_SQL.getDataTable(str);
        }
        public DataTable DonVi_Pharma()
        {
            string str = string.Format("exec dbo.usp_ThuNgan_ThuocNoiTru_DonViKho");
            return Uit.it_SQL.getDataTable(str);
        }
        public object SobnToaThuocNT( string noiphatthuoc,string madonviuser)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_SoBN_ToaThuoc '{0}','{1}'", noiphatthuoc,madonviuser);
            return Uit.it_SQL.ExecuteScalar(_sql);
        }
        public DataTable DanhSachToaThuoc( string tungay,string denngay,string madv)
        {
            string _sql = string.Format("exec dbo.usp_ThuocNoiTru_TimKiem_DSToa '{0}','{1}','{2}'", tungay,denngay,madv);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable ToaThuoc_ChiTiet(string sobn)
        {
            string _sql = string.Format("dbo.usp_ThuocNoiTru_ChiTiet '{0}'",sobn);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable NhapVien_ToaThuoc_ChiTiet(string sohs)
        {
            string _sql = string.Format("exec dbo.usp_NhapVien_ThuocNoiTru '{0}'", sohs);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public object kiemtrachuyenkhole(string sophieu)
        {
            string _sql = string.Format("dbo.usp_ThuNgan_ThuocNoiTru_pharmaLot_PXLDTLLot_Insert_ToaPK_KiemTraTonTai '{0}'", sophieu);
            return Uit.it_SQL.ExecuteScalar(_sql);
        }
        public bool Chuyenkholeduoc(string sonhapvien ,string sophieu)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_Noitru_chuyentoathuocdenkhole '{0}','{1}'", sonhapvien,sophieu);
            return Uit.it_SQL.ExecuteNonQuery(_sql);
        }
        // PhKham Kholetmp_toapk
        public string Insert_kholetmp_toapk(int bdid ,float slg)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_ThuocNoiTru_Kholtmp_toapk_Insert {0},{1}", bdid, slg);
            return _sql;
        }
        public string Delete_kholetmp_toapk(int bdid ,float slg)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_ThuocNoiTru_Kholtmp_toapk_Delete {0},{1}", bdid, slg);
            return _sql;
        }
        
        public DataTable BangKeThuoc(string madv ,string sonhapvien)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_ThuocNoiTru_BangKeKhai '{0}','{1}'", madv,sonhapvien);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable PhieuPhatThuoc(string sophieu)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_ThuocNoiTru_PhieuPhatThuoc '{0}'",sophieu);
            return Uit.it_SQL.getDataTable(_sql);
        }
        public DataTable LyDoTraThuoc()
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_ThuocNoiTru_lydotrathuoc");
            return Uit.it_SQL.getDataTable(_sql);
        }
        
        
        #endregion

    }
}
